<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@ page isELIgnored="false" %>
<!DOCTYPE HTML>
<html>
  <head>
    <base href="<%=basePath%>">
    <title>李宁体育管理系统</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">
	<link href="css/style.min862f.css?v=4.1.0" rel="stylesheet">
	<link href="css/bootstrap.min14ed.css?v=3.3.6" rel="stylesheet">
	<link href="css/font-awesome.min93e3.css?v=4.4.0"rel="stylesheet">
     <link href="css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="css/plugins/chosen/chosen.css" rel="stylesheet">
    <link href="css/plugins/colorpicker/css/bootstrap-colorpicker.min.css" rel="stylesheet">
    <link href="css/plugins/cropper/cropper.min.css" rel="stylesheet">
    <link href="css/plugins/switchery/switchery.css" rel="stylesheet">
    <link href="css/plugins/datapicker/datepicker3.css" rel="stylesheet">
    <link href="css/plugins/awesome-bootstrap-checkbox/awesome-bootstrap-checkbox.css" rel="stylesheet">
    <link href="css/plugins/clockpicker/clockpicker.css" rel="stylesheet">
    <link href="css/animate.min.css" rel="stylesheet">
    <link href="css/style.min862f.css?v=4.1.0" rel="stylesheet"><base target="_blank"> 
    <style type="text/css">
	.feed-activity-list .feed-element {
		border-bottom: 1px solid #e7eaec;
	}
	
	.feed-element, .media-body {
		overflow: hidden;
	}
	
	.feed-element, .feed-element .media {
		margin-top: 15px;
	}
	
	.feed-element {
		padding-bottom: 15px;
	}
	.ibox-content {
    background-color: #fff;
    color: inherit;
    padding: 15px 20px 20px;
    border-color: #e7eaec;
    -webkit-border-image: none;
    -o-border-image: none;
    border-image: none;
    border-width: 1px 0;
}
.filehidden {}
</style>
  </head>
  <body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>修改投票</h5>

                    <div class="ibox-tools">
                        <a class="collapse-link">
                            <i class="fa fa-chevron-up"></i>
                        </a>
                        <a class="close-link">
                            <i class="fa fa-times"></i>
                        </a>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!-- Panel Other -->
    <div class="ibox float-e-margins" id="tableShow">
        
            <div class="row m-t">
                <div class="col-sm-12">
                      <form class="form-horizontal m-t"  id="votingVipActivityForm">
                      <div class="ibox-content">
                      <div class="feed-activity-list">
                      <div class="feed-element ">
									<div class="form-group">
									<input type="hidden" class="form-control" name="id" id="id" maxlength="25" value="${activity.id }"></input>
									    <label class="col-sm-2 control-label">活动标题</label><font color="red">*</font>
									    <div class="col-sm-3">
											<input type="text" class="form-control" name="title" id="title" maxlength="25" value="${activity.title }" placeholder="活动名称(不少于5个字符)"></input>
									    </div>
									    <span id="error_title" style="color: red">*</span>
									</div>
										<div class="form-group">
									    <label class="col-sm-2 control-label">活动状态</label><font color="red">*</font>
										     <div class="col-sm-3">
											<select data-placeholder="状态" name="state"
												style="width: 250px;" class="chosen-select" tabindex="2">
												<option value="0" selected>进行中</option>
												<option value="1"<c:if test="${activity.state ==1}">selected</c:if>>已结束</option>
											</select>
											</div>
									</div>
									<div class="form-group">
										<label class="col-sm-2 control-label">活动时间</label><font color="red">*</font>
										<div class="col-sm-3">
											<input type="text" class="form-control" name="beginTime" id="beginTime" value="<fmt:formatDate value="${activity.beginTime }" pattern="yyyy-MM-dd HH:mm:ss"/>" placeholder="开始时间"></input>
										</div>
										<span id="error_beginTime" style="color: red">*</span>
									</div>
									<div class="form-group">
										<label class="col-sm-2 control-label"></label><font color="red">*</font>
										<div class="col-sm-3">
											<input type="text" class="form-control" name="endTime" id="endTime"  value="<fmt:formatDate value="${activity.endTime }" pattern="yyyy-MM-dd HH:mm:ss"/>" placeholder="结束时间"></input>
										</div>
										<span id="error_endTime" style="color: red">*</span>
									</div>
									
									<div class="form-group">
										<label class="col-sm-2 control-label">活动人数</label><font color="red">*</font>
										<div class="col-sm-3">
											<input type="number" class="form-control" name="joinNum" id="joinNum" value="${activity.joinNum }" placeholder="人数" maxlength="5"></input>
										</div>
										<span id="error_joinNum" style="color: red"></span>
									</div>
								
									</div>
									
								</div>


							<div class="ibox-content">
								<div class="form-group" id="Inputs">
								<c:forEach items="${voteList }" var="vote" varStatus="i" >

									<div class="goToSaveProblem">
										<div class="ibox-title">
											<h5>问题${i.count }</h5>

											<div class="ibox-tools">
												<a class=""> <i class="fa fa-times"></i>
												</a>
											</div>
										</div>
										<div class="ibox-content">

											<div class="form-group">
												<input type="hidden" id="id${i.count }"name="id${i.count }" value="${vote.id }"></input>
												<input type="hidden" id="activityId${i.count }"name="activityId${i.count }" value="${vote.activityId }"></input> 
												 <label class="col-sm-2 control-label">标题</label>
												 <font color="red">*</font>
												<div class="col-sm-3">
													<input type="text" class="form-control"
														name="title${i.count }" id="title${i.count }"
														maxlength="20" placeholder="请填写问题的标题" value="${vote.title }"></input>
												</div>
											</div>
											<div class="form-group">
												<label class="col-sm-2 control-label"></label>
												<div class="col-sm-3">
													<input type="radio" name="type${i.count }"
														id="type${i.count }" value="1"  <c:if test="${1 == vote.type}">checked="checked"</c:if>  ></input>&nbsp;&nbsp;单选
													&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="radio"
														name="type${i.count }" id="type${i.count }" value="2" <c:if test="${2 == vote.type}">checked="checked"</c:if>  ></input>&nbsp;&nbsp;多选
												</div>
											</div>
											<div class="feed-element">
												<div class="media-body ">
													<div id="InputsWrapper">
													<c:if test="${'[]'  != vote.vipOptionList}">
													<c:forEach items="${vote.vipOptionList }" var="option" varStatus="k">
													
													<div class="form-group">
								    	            
								    	           <label class="col-sm-2 control-label">选项${k.count }</label>
								    	           <div class="col-sm-3">
								    	           <input type="text" maxlength="20" name="wt${i.count }${k.count }" id="wt${i.count }${k.count }" value="${option.name }" class="form-control"/></input>
								    	           <input type="hidden" maxlength="20" name="id${i.count }${k.count }" id="id${i.count }${k.count }" value="${option.id }" class="form-control"/></input>
								    	            </div>
								    	            
								    	            
								    	        	<div class="ibox float-e-margins col-sm-8" style="margin-left:90px;margin-top:30px">
									    	        <div class="form-group">
									    	        <input class="filehidden" id="lefile${i.count }${k.count }" name="lefile${i.count }${k.count }" type="file"  onchange="upLodeFile(this,${i.count },${k.count })" style="opacity: 0;" >
									    	        <div class="col-sm-2">
									    	             <a class="btn btn-info" onclick="$('input[name=lefile${i.count }${k.count }]').click();">选择图片</a>
									    	             </div>
									    	             <div class="col-sm-4">
									    	            <input id="photoCover${i.count }${k.count }" name ="photoCover${i.count }${k.count }" on class="input-large form-control" value="${option.img }" type="text" style="height:30px;">  
									    	              </div>
									    	              <div class="file-box">
								                          <div class="file">
								                              <a>
								                                  <span class="corner"></span>
								                                  <div class="image" >
								                                      <img   id="img${i.count }${k.count }" alt="" class="img-responsive" src="${option.img }" style="width:100%;height:100%">
								                                  </div>
								                             </a>
								                          </div>
								                      </div>
									    	        </div>
									    	        <!-- <a href="#" class="removeclass">删 除</a>&nbsp;&nbsp;&nbsp;&nbsp;
								    	            <span id="imgHint'+ x +'" class="removespan" style="color:red">图片比例1:1，建议尺寸120x120px</span> -->
									    	        </div>
									    	        
									    	        </div>
													
													</c:forEach>
													</c:if>
													</div>
												</div>
											</div>
										</div>
										</div>
									</c:forEach>

									</div>

									<div class="feed-element">
								<div class="form-group">
                                         <div class="col-sm-4 col-sm-offset-3">
                                          <button class="btn btn-primary" type="submit" >保  存</button>
                                          &nbsp;<button class="btn btn-info" type="button" onclick="goBackVipActivity()">返  回</button>
                                         </div>
                                    </div>
                                </div>
                             </div>
                             </div>
                    </form>
                </div>
            </div>
        
        
  
    </div>
    <div style="display: none;position: relative;
    top: -50px;" class="modal" id="myModal" tabindex="-1"role="dialog" aria-labelledby="myModalLable" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <%--<button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>--%>
                <h4 class="modal-title" id="myModallabel">消息提示</h4>
            </div>
            <div class="modal-body">
                <span id="deletecontent"></span>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary" id="confirm" onclick="confirm()">确定删除</button>
                <button type="button" class="btn btn-default" data-dismiss="modal" id="cancel" onclick="cancel()">取消删除</button>

            </div>
        </div>
    </div>
</div>
</div>


<script src="js/jquery.min.js?v=2.1.4"></script>
<script src="js/bootstrap.min.js?v=3.3.6"></script>
<script src="js/content.min.js?v=1.0.0"></script>
<script src="js/jquery.validate.js"></script>
<script src="js/jquery.serializeObject.js"></script>
<script src="js/plugins/chosen/chosen.jquery.js"></script>
<!--时间选择-->
<script src="js/plugins/layer/laydate/laydate.js"></script>
<script src="js/plugins/prettyfile/bootstrap-prettyfile.js"></script>
<script src="js/plugins/ajaxfileupload.js"></script>
<script src="js/plugins/layer/layer.js"></script>
	<script type="text/javascript">
	var config = {
			".chosen-select" : {},
			".chosen-select-deselect" : {
				allow_single_deselect : !0
			},
			".chosen-select-no-single" : {
				disable_search_threshold : 10
			},
			".chosen-select-no-results" : {
				no_results_text : "Oops, nothing found!"
			},
			".chosen-select-width" : {
				width : "95%"
			}
		};

		for ( var selector in config)
			$(selector).chosen(config[selector]);
	
		var upLodeFile=function(a,vote,option) { 
    		fileUpload(a,vote,option);
			$("#photoCover"+vote+""+option+"").val($(a).val());  
			}; 
	
    $(document).ready(function() {  
    	$("#Inputs").on("click",".fa-times",function(){
    		$(this).parent().parent().parent().parent().remove();
    	})
    	
    	
    	
    	 
    	$("#votingVipActivityForm").validate({
    		rules: {
    			title: {
    				required: true,
    				rangelength:[3,20]
    			},
    			beginTime: {
    				required: true,
    			},
    			endTime: {
    				required: true,
    				
    			},
    			joinNum: {
    				required: true,
    				
    			}
    		},
    		messages:{
    			title:{
    				required: "用户名不能为空"
    			},
    			beginTime:{
    				required: "开始时间不能为空"
    			},
    			endTime:{
    				required: "结束时间不能为空"
    			},
    			joinNum:{
    				required: "参与人数不能为空"
    			}
    		
    		},
    		errorPlacement: function(error, element) {
    			$( element ).closest( "form" ).find( "span[id='error_" + element.attr( "name" ) + "']" ).append( error );
    		},
    	    onkeyup: false,
    		submitHandler:function(){
    			var roleForm = $("#votingVipActivityForm").serializeObject();
    			console.log(JSON.stringify(roleForm));
    			jQuery.ajax({
    				type: "post",
    			    url: "<%=path%>/activity/toUpdateActivityVote",
    			    contentType: "application/json",
    			    data: JSON.stringify(roleForm),
    			    beforeSend:function() {
    			    	$("#progress").modal();
    			    	$("#loading").html("正在提交用戶数据，请稍候...");

    			    },
    			    complete:function(data) {
    			    	$("#progress").modal('hide');
    			    	$("#loading").html("");
    			    }, 
    			    success: function (data) {
    			    	if(data.status==200){
    			    		parent.layer.msg("修改投票活动成功!",{time: 1000},function(){goBackVipActivity();});
    			    	}else{
    			    		parent.layer.msg("修改投票活动失败!");			    		
    			    	}
    			    },
    			    error: function () {
    			    	parent.layer.msg("修改投票活动失败,请联系管理员!");
    			    }	
    			});
    		}
    		
    	}); 
    	}); 
	
	
	
	
		/* 
		var config = {
			".chosen-select" : {},
			".chosen-select-deselect" : {
				allow_single_deselect : !0
			},
			".chosen-select-no-single" : {
				disable_search_threshold : 10
			},
			".chosen-select-no-results" : {
				no_results_text : "Oops, nothing found!"
			},
			".chosen-select-width" : {
				width : "95%"
			}
		};
 */
		//日期选择框
		var start = {
			elem : "#beginTime",
			format : "YYYY-MM-DD hh:mm:ss",
			min : laydate.now(),
			max : "2099-06-16",
			istime : true,
			istoday : false,
			choose : function(datas) {
				end.min = datas;
				end.start = datas
			}
		};
		var end = {
			elem : "#endTime",
			format : "YYYY-MM-DD hh:mm:ss",
			min : start,
			max : "2099-06-16",
			istime : true,
			istoday : false,
			choose : function(datas) {
				start.max = datas
			}
		};
		laydate(start);
		laydate(end);
		
		
		var goBackVipActivity=function(){
			window.location.href="<%=basePath%>activity/toVotePage"
		}
		
	var	fileUpload = function(sender,x,y) {
			$.ajaxFileUpload({
				url : '<%=basePath%>activity/voteEditFileUpload', // 用于文件上传的服务器端请求地址
				type : 'post',
				data : {
					"index":x,
					"extension" : ".png,.jpg,.jpeg"
				}, // JSON格式
				secureuri : false, // 一般设置为false
				fileElementId : 'lefile'+x+''+y+'', // 文件上传空间的id属性 <input type="file" id="file" name="file" />
				dataType : 'json', // 返回值类型 一般设置为json
				global : true,
				success : function(response, status) { // 服务器成功响应处理函数
				  if (response.status==200) {
					  $("#photoCover"+x+""+y+"").val(response.data);
					  $("#img"+x+""+y+"").attr("src",response.data);
						
					} 
				},
				error : function(data, status, e) {// 服务器响应失败处理函数
					/* _showInfoMessage(e, 'error'); */
					alert(x);
				}
			});
		}
    
	</script>

  </body>
  <script src="js/plugins/dropzone/dropzone.js"></script>
</html>
